//@author A0105735J
#include "CommandUpdate.h"

CommandUpdate::CommandUpdate(void){
	type = CommandTypeUpdate;
}

CommandUpdate::~CommandUpdate(void){}

void CommandUpdate::setEvent(Event* tempEvent){
	theEvent = tempEvent;
}

void CommandUpdate::setID(int id){
	displayID = id;
}

Feedback CommandUpdate::execute(Receiver* receiver){
	Logger::instance()->LogMessage("trying to update one event");	

	undoUpdateEvent = receiver->getTargetEvent(displayID,1)->clone();

	return receiver->updateCommand(displayID,theEvent);
}

Feedback CommandUpdate::undo(Receiver* receiver){
	Logger::instance()->LogMessage("trying to undo the last update");
	Event* targetEvent = receiver->getTargetEvent(undoUpdateEvent->getSearchID(),2);
	return receiver->updateCommand(targetEvent->getDisplayID(),undoUpdateEvent);
}

Event* CommandUpdate::getEvent(){
	return theEvent;
}